package vn.anhqn.englishsentensetranslator.adapter;

import java.util.List;

import vn.anhqn.englishsentensetranslator.R;
import vn.anhqn.englishsentensetranslator.model.Category;
import vn.anhqn.englishsentensetranslator.widget.HeverticalTextView;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class CategorySpinnerAdapter extends BaseAppAdapter<Category> {

	public CategorySpinnerAdapter(List<Category> list, Context c) {
		super(list, c);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		return getCustomView(position, convertView, parent);
	}

	@Override
	public View getDropDownView(int position, View convertView, ViewGroup parent) {
		return getCustomView(position, convertView, parent);
	}

	public View getCustomView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
		ViewHolder holder = new ViewHolder();
		if (view == null) {
			LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = inflater.inflate(R.layout.item_category_spinner, null);
			holder.tvTitle = (HeverticalTextView) view.findViewById(R.id.tv_item_spinner);
			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}
		Category item = getItem(position);
		holder.tvTitle.setText(item.getName());
		return view;
	}
	
	private class ViewHolder {
		HeverticalTextView tvTitle;
	}
}
